//
//  WYPersonHeaderView.m
//  Boss
//
//  Created by admin on 2018/6/25.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYPersonHeaderView.h"
#import "WYUserMessage.h"
@interface WYPersonHeaderView()

@property (nonatomic,strong)UIImageView *userImageView;
@property (nonatomic,strong)UILabel *nameLabel;
@property (nonatomic,strong)UILabel *positionLabel;
@property (nonatomic,strong)UIImageView *goldImageView;
@property (nonatomic,strong)UIImageView *rightImageView;

@end
@implementation WYPersonHeaderView

-(instancetype)init
{
    if (self = [super init]) {
        [self createSubViews];
    }
    return self;
}
//-(instancetype)initWithFrame:(CGRect)frame
//{
//    if (self = [super initWithFrame:frame]) {
//        [self createSubViews];
//    }
//    return self;
//}

-(void)createSubViews
{
    UIView *view =[[UIView alloc]init];
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(0);
        make.height.mas_equalTo(100);
    }];
    view.backgroundColor = [UIColor clearColor];
    
    
    
    UIImageView *userImageView = [[UIImageView alloc]init];
    [self addSubview:userImageView];
    self.userImageView = userImageView;
    [userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(10);
        make.width.height.mas_equalTo(66);
    }];
    userImageView.image =[UIImage imageNamed:@"logo_place"];
    userImageView.userInteractionEnabled = YES;
    [userImageView setCornerRadius:33.f];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickUserImageView:)];
    [userImageView addGestureRecognizer:tap];
    
    
    
    
    
    
    
    
    
    
    self.nameLabel  = [[UILabel alloc]init];
    [self addSubview:self.nameLabel ];
    [self.nameLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(userImageView.mas_right).offset(16);
        make.top.mas_equalTo(19);
    }];
    self.nameLabel .text = @"";
    self.nameLabel .textColor = [UIColor whiteColor];
    self.nameLabel .font = kFontSystemBIgger2(18);
    
    UILabel *positionLabel = [[UILabel alloc]init];
    [self addSubview:positionLabel];
    self.positionLabel = positionLabel;
    [positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel .mas_bottom).offset(5);
        make.left.equalTo(userImageView.mas_right).offset(16);
    }];
    
    positionLabel.textColor = [UIColor whiteColor];
    positionLabel.font = kFontSystemBIgger2(14);
    positionLabel.text = @"";
    
    self.backgroundColor = kColorMainColor;
//    UIButton
    
    UIImageView *goldImageView = [[UIImageView alloc]init];
    [self addSubview:goldImageView];
    
    [goldImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.nameLabel);
        make.left.equalTo(self.nameLabel.mas_right).offset(5);
    }];
   // goldImageView.image = [UIImage imageNamed:@"gold_vip"];
    self.goldImageView = goldImageView;
    goldImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickVipImageView:)];
    [goldImageView addGestureRecognizer:ges];
    
    UIImageView *rightImageView = [[UIImageView alloc]init];
    [self addSubview:rightImageView];
    [rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(self);
    }];
    
    rightImageView.image = [UIImage imageNamed:@"right"];
    self.rightImageView = rightImageView;
   
    
    
    UIView *doneView = [[UIView alloc]init];
    [view addSubview:doneView];
    self.doneView = doneView;
    [doneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(40);
    }];
    doneView.hidden = YES;
    doneView.backgroundColor = [UIColor hexStringToColor:@"#fffaf2" alpha:1.0];
    
    UILabel *doneLabel =[[UILabel alloc]init];
    [doneView addSubview:doneLabel];
    [doneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(doneView);
    }];
    
    doneLabel.textColor = [UIColor hexStringToColor:@"#f9a73b" alpha:1.0];
    doneLabel.font = [UIFont systemFontOfSize:16];
    doneLabel.text = @"完善资料可快速提升曝光";
    
    UIButton *doneBtn = [[UIButton alloc]init];
    [doneView addSubview:doneBtn];
    self.doneBtn = doneBtn;
    [doneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(doneView);
        make.height.mas_equalTo(25);
    }];
    
    [doneBtn setBorderWithWidth:kLineHeight andColor:[UIColor hexStringToColor:@"f9a73b" alpha:1.0]];
    [doneBtn setTitle:@" 去完善 " forState:UIControlStateNormal];
    [doneBtn setTitleColor:[UIColor hexStringToColor:@"#f9a73b" alpha:1.0] forState:UIControlStateNormal];
    doneBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    
    
    UIButton *button = [[UIButton alloc]init];
    [view addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(userImageView.mas_right).offset(5);
        make.top.right.mas_equalTo(0);
        make.bottom.equalTo(doneView.mas_top).offset(0);
    }];
    
    // [button setBackgroundColor:[UIColor clearColor]];
    
    [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
}
-(void)clickButton
{
    if ([self.delegate respondsToSelector:@selector(gotoVipAction)]) {
        [self.delegate gotoVipAction];
    }
}




-(void)setInfo:(WYMyInfo *)info
{
    _info = info;
    
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:info.url] placeholderImage:[UIImage imageNamed:@"ic_defult_avatar"]];
    self.nameLabel.text = info.userName;
    self.positionLabel.text =[NSString stringWithFormat:@"%@ %@",@"",info.position?info.position:@""] ;

    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    [self.goldImageView showVipImageViewStatusWithVipId:userMessage.vipId];
    if (info.userPerfectStatus.integerValue) {
        self.doneView.hidden = YES;
    }else{
        self.doneView.hidden = NO;
        [self addView];
        [self.rightImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self).offset(-20);
        }];
    }
}
-(void)addView
{
    
}




-(void)clickUserImageView:(UITapGestureRecognizer *)ges
{
    if ([self.delegate respondsToSelector:@selector(gotoPersonMessage)]) {
        [self.delegate gotoPersonMessage];
    }
}
-(void)clickVipImageView:(UITapGestureRecognizer *)ges
{
//    if ([self.delegate respondsToSelector:@selector(gotoVipAction)]) {
//        [self.delegate gotoVipAction];
//    }
}


@end
